package com.qk.controller;

import com.qk.common.PageResult;
import com.qk.common.Result;
import com.qk.entity.Activity;
import com.qk.service.ActivityService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/activities")
public class ActivityController {
    @Autowired
    private ActivityService activityService;

    @GetMapping
    public Result page(Integer channel,Integer type,Integer status,
                       @RequestParam(value = "page",defaultValue = "1") Integer page,
                       @RequestParam(value = "pageSize",defaultValue = "10") Integer pageSize){

        log.info("channel = {}, type = {}, status = {}, page = {}, pageSize = {}  ",
                channel, type, status, page, pageSize);
        PageResult<Activity> pageResult = activityService.selectPage(channel,type,status,page,pageSize);
        return Result.success(pageResult);
    }

    @PostMapping
    public Result insertActivity(@RequestBody Activity activity){
        log.info("activity = {}", activity);
        activityService.insert(activity);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getActivityById(@PathVariable Integer id){
        log.info("id = {}", id);
        Activity activity = activityService.selectById(id);
        return Result.success(activity);
    }

    @PutMapping
    public Result updateActivity(@RequestBody Activity activity){
        log.info("activity = {}", activity);
        activityService.updateActivity(activity);
        return Result.success();
    }

    @DeleteMapping
    private Result deleteActivityById(@RequestParam Integer id){
        log.info("id = {}", id);
        activityService.delectById(id);
        return Result.success();
    }

    @GetMapping("/type/{type}")
    public Result getActivityByType(@PathVariable Integer type){
        log.info("type = {}", type);
        List<Activity> activitys = activityService.selectByType(type);
        return Result.success(activitys);
    }

//    @GetMapping("/list")
//    public Result getActivityList(){
//        List<Activity> activityList = activityService.list();
//        return Result.success(activityList);
//    }



}
